package com.boot.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class IndexController {

    @GetMapping({"","/index"})
    public String index(Model model){
        Subject subject = SecurityUtils.getSubject();
        model.addAttribute("subject",subject);

        return "index";
    }

    @GetMapping("/other")
    public String other(Model model){
        Subject subject = SecurityUtils.getSubject();
        model.addAttribute("subject",subject);

        return "other";
    }

    @GetMapping("/authenticated")
    public String authenticated(Model model){
        Subject subject = SecurityUtils.getSubject();
        model.addAttribute("subject",subject);

        return "authenticated";
    }

    @GetMapping("/role")
    public String role(Model model){
        Subject subject = SecurityUtils.getSubject();
        model.addAttribute("subject",subject);
        return "role";
    }

    @GetMapping("/permission")
    public String permission(Model model){
        Subject subject = SecurityUtils.getSubject();
        model.addAttribute("subject",subject);
        return "permission";
    }

    @GetMapping("/logout")
    public String logout(){
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "redirect:/login";
    }

}
